package hotel.switchs.oversea.biz.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import hotel.base.oversea.constant.*;
import hotel.base.oversea.constant.enums.*;
import hotel.base.oversea.dto.meituan.MtHotelGoodsBookRuleDto;
import hotel.base.oversea.dto.meituan.MtHotelGoodsDto;
import hotel.base.oversea.dto.meituan.MtHotelGoodsInvoiceDto;
import hotel.base.oversea.dto.switchs.SwitchCreateRoomDto;
import hotel.base.oversea.entity.SwitchHotelActiveTagEntity;
import hotel.base.oversea.entity.SwitchPriceBaseSetEntity;
import hotel.base.oversea.entity.master.CompareHotelBasicRoom;
import hotel.base.oversea.service.impl.BaseServiceImpl;
import hotel.base.oversea.utils.*;
import hotel.base.oversea.utils.DateUtil;
import hotel.base.oversea.vo.MtOrderCheckVo;
import hotel.base.oversea.vo.PirceModelVo;
import hotel.base.oversea.vo.meituan.MtHotelDownVo;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsCheckFailOneVo;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsCheckFailVo;
import hotel.base.oversea.vo.meituan.request.goods.MtHotelGoodsStatusDetailStateVo;
import hotel.base.oversea.vo.meituan.request.room.CompareRoomForFpVO;
import hotel.base.oversea.vo.meituan.response.goods.MtHotelGoodsPriceBaseDetailVo;
import hotel.switchs.oversea.api.VO.SwitchHotelUpVo;
import hotel.switchs.oversea.api.VO.request.*;
import hotel.switchs.oversea.api.entity.*;
import hotel.switchs.oversea.biz.config.service.RedisService;
import hotel.switchs.oversea.biz.mapper.*;
import hotel.switchs.oversea.biz.service.*;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.multipart.MultipartFile;
import tk.mybatis.mapper.entity.Example;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.*;

/**
 * @Auther: lmf
 * @Date: 2020/09/23/14:23
 * @Description:
 */
@Service
@Slf4j
public class switchHotelUpServiceImpl extends BaseServiceImpl<SwitchHotelUpEntity> implements SwitchHotelUpService {
    @Autowired
    SwitchHotelUpMapper switchHotelUpMapper;
    @Autowired
    SwitchSubHotelInfoService switchSubHotelInfoService;
    @Autowired
    SwitchHotelUpLogMapper switchHotelUpLogMapper;
    @Autowired
    SwitchCreateRoomMapper switchCreateRoomMapper;
    @Autowired
    SwitchRestTempaleUtilsService switchRestTempaleUtilsService;
    @Autowired
    SwitchPushRoomService switchPushRoomService;
    @Autowired
    RedisService redisService;
    @Autowired
    RestTemplate restTemplate;
    @Autowired
    StringRedisTemplate stringRedisTemplate;
    @Autowired
    SwitchHotelActiveTagMapper switchHotelActiveTagMapper;

    @Autowired
    SwitchCreateRoomFailureMapper switchCreateRoomFailureMapper;

    @Autowired
    SwitchBasicRoomTypeService switchBasicRoomTypeService;

    @Autowired
    SwitchCreateSubHotelMapper switchCreateSubHotelMapper;

    @Autowired
    SwitchRoomPriceService switchRoomPriceService;
    @Autowired
    SwitchPushRoomLogMapper switchPushRoomLogMapper;

    @Autowired
    SwitchCreateBasicRoomMapper switchCreateBasicRoomMapper;


    /**
     * 美团的地址
     */
    private static final String MEI_TUAN_URL = CommonUrlConstants.MEITUAN_HOST + "/";
    /**
     * 标记是否上架
     */
    private final static String SWITCH_HOTEL_UP_TIME = "switch_hotel_up_time";

    /**
     * 1. 线程池显示的调用了shutdown()之后，再向线程池提交任务的时候，如果你配置的拒绝策略是ThreadPoolExecutor.AbortPolicy的话，这个异常就被会抛出来。
     * 2. 当你的排队策略为有界队列，并且配置的拒绝策略是ThreadPoolExecutor.AbortPolicy，当线程池的线程数量已经达到了maximumPoolSize的时候，你再向它提交任务，就会抛出ThreadPoolExecutor.AbortPolicy异常。
     * Executors.newFixedThreadPool(20)
     */
    //private ExecutorService executorService = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    //private ExecutorService executorServiceByHotel = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());

    /***
     * @Author: lmf
     * @Date: 2020/12/7
     * 下架全部酒店，保持在售状态
     */
    public Result<Object> downHotelAll(SetHotelUpVo setHotelUpVo) {
        new DownHotelThread(setHotelUpVo).run();
        return new Result<>(CommonConstants.SUCCESS, "下架中.......");
    }

    @Override
    public Result<Object> getUpHotelDesc() {
        List<Integer> list = switchHotelUpMapper.getUpHotelDesc();
        return new Result<>(GsonUtils.GsonString(list), "success");
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/7
     * 下架全部酒店
     */
    class DownHotelThread implements Runnable {
        private SetHotelUpVo setHotelUpVo;

        public DownHotelThread(SetHotelUpVo setHotelUpVo) {
            this.setHotelUpVo = setHotelUpVo;
        }

        @Override
        public void run() {
            long startTime = System.currentTimeMillis();
            //1.获取所有可以上架的酒店id
            List<Integer> ids = switchHotelUpMapper.selectSaleHotelList();
            List<List<Integer>> hotelIds = ListUtils.parititon(ids, 50);
            String idAll = "";
            int size = 0;
            log.info("=============当前的上架酒店长度为{}", hotelIds.size());
            int times = 0;
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities = new ArrayList<>();
            SwitchHotelUpLogEntity switchHotelUpLogEntity;
            for (List<Integer> h : hotelIds) {
                //crtip 关闭,其余渠道正常开售
                Map<String, Object> updateChannelVoMap = new HashMap<>();
                updateChannelVoMap.put("hotelIDs", hotelIds);
                updateChannelVoMap.put("cBookable", 0);
                updateChannelVoMap.put("qBookable", 1);
                updateChannelVoMap.put("channelABookable", 1);
                updateChannelVoMap.put("b2bBookable", 1);
                Result<Object> result= switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                if (result.getCode() == CommonConstants.SUCCESS) {
                    log.info("=========下架成功,这是第几次调用为{}===========", times++);
                    idAll += StringUtils.join(h, ",");
                    for (Integer hotelId : h) {
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(0);
                        switchHotelUpLogEntity.setUsername("system");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(h, ","),0);
                }
                try {
                    Thread.sleep(8000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
            long endTime = System.currentTimeMillis();
            log.info("==============下架发费的时间为{}", (endTime - startTime));
        }
    }


    /***
     * @Author: lmf
     * @Date: 2020/10/6
     * 全部售卖按钮
     */
    @SneakyThrows
    @Override
    public Result<Object> upHotelAllNew(SetHotelUpVo setHotelUpVo) {
        new UpHotelThread(setHotelUpVo).run();
        return new Result<>(CommonConstants.SUCCESS, "上架中.....");
    }

    class UpHotelThread implements Runnable {
        private SetHotelUpVo setHotelUpVo;

        public UpHotelThread(SetHotelUpVo setHotelUpVo) {
            this.setHotelUpVo = setHotelUpVo;
        }

        @Override
        public void run() {
            long startTime = System.currentTimeMillis();
            //1.获取所有可以上架的酒店id
            List<SwitchHotelUpVo> switchHotelUpVos = switchHotelUpMapper.selectHotelStatus(3);
            log.info("========上架前可循环一次所有上架酒店,目前有{}个酒店====", switchHotelUpVos.size());
            List<Integer> can = new ArrayList<>();
            for (SwitchHotelUpVo switchHotelUpVo : switchHotelUpVos) {
                Integer[] hotelId = new Integer[2];
                hotelId[0] = switchHotelUpVo.getMtHotelId();
                //调用美团接口检查是否有被拉入黑名单的酒店
                String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_HOTEL_FAILURE.getUrl();
                Map<String, Object> params = new HashMap<>();
                params.put("hotelIds", hotelId);
                Result<List<MtHotelDownVo>> result = switchRestTempaleUtilsService.sendReuestToMtCheckHotelFailure(url, params);
                List<MtHotelDownVo> mtHotelDownVos = result.getData();
                if (mtHotelDownVos.size() < 1) {
                    checkHotelGoodStatus(switchHotelUpVo.getHotelId());
                    can.add(switchHotelUpVo.getHotelId());
                } else {
                    for (MtHotelDownVo mtHotelDownVo : mtHotelDownVos) {
                        //0 下线  1 上线
                        if (mtHotelDownVo.getStatus() == 0) {
                            switchHotelUpMapper.updateHotelStatis(String.valueOf(switchHotelUpVo.getHotelId()), 0);
                        } else {
                            can.add(switchHotelUpVo.getHotelId());
                        }
                        checkHotelGoodStatus(switchHotelUpVo.getHotelId());
                    }
                }
            }
            List<List<Integer>> canHotelIds = ListUtils.parititon(can, 50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities = new ArrayList<>();
            if (canHotelIds.size() > 0) {
                for (List<Integer> list : canHotelIds) {
                    Integer[] hotelId = new Integer[list.size()];
                    Result<Object> result1 = pushHotelStatus(list.toArray(hotelId), 1);
                    if (result1.getCode() == CommonConstants.SUCCESS) {
                        switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","), 3);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer hotelIds : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(hotelIds);
                            switchHotelUpLogEntity.setUp(3);
                            switchHotelUpLogEntity.setUsername("system-全部售卖");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                    }
                    try {
                        Thread.sleep(9000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            if (switchHotelUpLogEntities.size() > 0) {
                switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
            }
            saveRedisCache(1);
            long endTime = System.currentTimeMillis();
            log.info("==========整体上架耗时时间为{}ms", (endTime - startTime));
        }
    }

    /**
     * 遍历酒店是否含有失效的产品
     */
    public void checkHotelGoodStatus(int hotelId) {
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(hotelId);
        String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_TEN_HOTELS_GOODS_FAILURE.getUrl();
        MtHotelGoodsCheckFailVo mtHotelGoodsCheckFailVo = new MtHotelGoodsCheckFailVo();
        List<MtHotelGoodsCheckFailOneVo> mtHotelGoodsCheckFailOneVos = new ArrayList<>();
        MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo = new MtHotelGoodsCheckFailOneVo();
        List<String> goodsIds = new ArrayList<>();
        int mtHotelId = 0;
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            goodsIds.add(String.valueOf(switchCreateRoomEntity.getMtGoodId()));
            mtHotelId = switchCreateRoomEntity.getMtHotelId();
        }
        mtHotelGoodsCheckFailOneVo.setGoodsIds(goodsIds);
        mtHotelGoodsCheckFailOneVo.setMtHotelId(String.valueOf(mtHotelId));
        mtHotelGoodsCheckFailOneVos.add(mtHotelGoodsCheckFailOneVo);
        mtHotelGoodsCheckFailVo.setHotels(mtHotelGoodsCheckFailOneVos);
        Result<List<MtHotelGoodsCheckFailOneVo>> result = switchRestTempaleUtilsService.sendReuestToMtCheckHotelGoodFailure(url, mtHotelGoodsCheckFailVo);
        List<MtHotelGoodsCheckFailOneVo> mtHotelGoodsCheckFailOneVos1 = result.getData();
        if (!ObjectUtils.isEmpty(mtHotelGoodsCheckFailOneVos1) && mtHotelGoodsCheckFailOneVos1.size() > 1) {
            for (MtHotelGoodsCheckFailOneVo mtHotelGoodsCheckFailOneVo1 : mtHotelGoodsCheckFailOneVos1) {
                List<String> goodsId = mtHotelGoodsCheckFailOneVo1.getGoodsIds();
                if (goodsId.size() > 1) {
                    for (String goodId : goodsId) {
                        //1.推送携程接口，设置售卖无效
                        SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomMapper.selectByMtGoodsIdAndHotelId(mtHotelId, Integer.valueOf(goodId));
                        if (!ObjectUtils.isEmpty(switchCreateRoomEntity)) {
                            SetRoomOnlineOfflineVo setRoomOnlineOfflineVo = new SetRoomOnlineOfflineVo();
                            setRoomOnlineOfflineVo.setRoomTypeId(switchCreateRoomEntity.getRoomId());
                            setRoomOnlineOfflineVo.setHotelId(switchCreateRoomEntity.getHotelId());
                            setRoomOnlineOfflineVo.setChannel("Ctrip");
                            setRoomOnlineOfflineVo.setRoomStatus(2);
                            Result<Object> results = switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                            setRoomOnlineOfflineVo.setChannel("Qunar");
                            switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                            //设置无效成功
                            if (result.getCode() == CommonConstants.SUCCESS) {
                                //2.添加到产品失效库
                                SwitchCreateRoomFailureEntity switchCreateRoomFailureEntity = new SwitchCreateRoomFailureEntity();
                                BeanUtils.copyProperties(switchCreateRoomEntity, switchCreateRoomFailureEntity);
                                switchCreateRoomFailureEntity.setId(switchCreateRoomFailureEntity.getId() + StringUtil.getFourRandom());
                                int flag = switchCreateRoomFailureMapper.insert(switchCreateRoomFailureEntity);
                                //3.从产品库删除
                                if (flag > 0) {
                                    switchCreateRoomMapper.deleteRoomInfoByMtHotelIdAndMtGoodId(mtHotelId, goodId);
                                    //4.从缓存中清除
                                    String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                                    redisService.remove(key);
                                    String key3 = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                                    if (redisService.exists(key3)) {
                                        redisService.remove(key3);
                                    }
                                }
                            }
                            try {
                                Thread.sleep(6000);
                                setRoomOnlineOfflineVo.setChannel("ChannelA");
                                switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                                Thread.sleep(6000);
                                setRoomOnlineOfflineVo.setChannel("B2B");
                                switchBasicRoomTypeService.setRoomOnlineOffline(setRoomOnlineOfflineVo);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        } else {
                            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
                        }
                    }
                }
            }
        }

    }

    /**
     * 遍历售卖房型
     *
     * @return
     */
    @Override
    public Result<Object> runHotel() {
        log.info("==========調用调用下单前校验更新携程,跑上架的酒店==========");
        long startTime = System.currentTimeMillis();
        //1.判断是否今日调用过上架接口
        String key = CommonConstants.SWITCH_PUSH_ROOM_THREAD_NUM;
        redisService.set(key, 3);
        int total = 50000;
        //上架的总售卖房型个数
        int num = switchHotelUpMapper.getRoomIdOfHotelNum();
        String upTime = "";
        if (!redisService.exists(SWITCH_HOTEL_UP_TIME)) {
            log.info("=======================没有酒店进行售卖，暂时不去调用美团下单效验接口====================================");
            return new Result<>("没有酒店进行售卖，暂时不去调用美团下单效验接口");
        }
        upTime = (String) redisService.get(SWITCH_HOTEL_UP_TIME);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String now = formatter.format(date);
        if (upTime.equals(now)) {
            total = total - num;
        }
        String check_num_key = "switch_call_mt_order_check_num";
        int useNum = 0;
        if (redisService.exists(check_num_key)) {
            useNum = (int) redisService.get(check_num_key);
        }
        if (useNum > total) {
            log.info("=======================调用美团下单效验接口次数已经用完了====================================");
            return new Result<>("用完了");
        }
        //获取遍历
        //   List<Integer> ids = switchHotelUpMapper.selectIds(1);
        List<Integer> ids = new ArrayList<>();
        List<List<Integer>> hotelIds = ListUtils.parititon(ids, 3);
        log.info("=======总共需要调用{}次=========", hotelIds.size());
        int times = 0;
        log.info("==========開始進行酒店遍歷===================");
        for (List<Integer> list : hotelIds) {
            Result<Object> result = execHotelUp(list);
            log.info("===================第{}次上架酒店，6s/次", times++);
        }
        long endTime = System.currentTimeMillis();
        redisService.set(key, 12);
        log.info("==========酒店遍歷完成,改為12個線程===================");
        useNum += num;
        redisService.set(check_num_key, useNum);
        log.info("==========整体上架耗时时间为{}ms", (endTime - startTime));
        return new Result<>();
    }

    /**
     * @author: lmf
     * @time: 2020/10/16 17:15
     * 清除所有缓存
     */
    @Override
    public Result<Object> removeALl() {
        List<SwitchCreateRoomEntity> list = switchCreateRoomMapper.selectAll();
        tab:
        for (SwitchCreateRoomEntity switchCreateRoomEntity : list) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            if (redisService.exists(key)) {
                redisService.remove(key);
                log.info("========key存在,刪除成功======");
            } else {
                continue tab;
            }

        }
        List<SwitchCreateRoomFailureEntity> list2 = switchCreateRoomFailureMapper.selectAll();
        tab:
        for (SwitchCreateRoomFailureEntity switchCreateRoomEntity : list2) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            if (redisService.exists(key)) {
                redisService.remove(key);
                log.info("========key存在,刪除成功======");
            } else {
                continue tab;
            }
        }
        String patten = "selling_the_house_type_*";
        Set<String> keys = stringRedisTemplate.keys(patten);
        if (!ObjectUtil.isEmpty(keys) && keys.size() > 0) {
            for (String o : keys) {
                redisService.remove(o);
                log.info("========key存在,刪除成功======");
            }
        }
        return new Result<>(CommonConstants.SUCCESS, "删除成功");
    }

    /**
     * 批量上架
     */
    @SneakyThrows
    public Result<Object> execHotelUp(List<Integer> list) {
        ExecutorService executorServiceByHotel = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
        List<Future<Result<Object>>> futureList = new ArrayList<>();
        for (int i = 0; i < list.size(); i++) {
            if (!executorServiceByHotel.isShutdown()) {
                Future<Result<Object>> future = executorServiceByHotel.submit(new switchHotelUp(list.get(i), "酒店线程" + list.get(i)));
                futureList.add(future);
                Thread.sleep(200);
            }

        }
        executorServiceByHotel.shutdown();
        while (true) {
            if (executorServiceByHotel.isTerminated()) {
                for (Future<Result<Object>> future : futureList) {
                    log.info("=====执行完毕,执行结果为{}======", future.get().getMsg());
                }
                break;
            }
        }
        return new Result<>();
    }

    /**
     * 上架前推送房态价格库存
     */
    @SneakyThrows
    public Result<Object> pushRoomPriceAndStatus(Integer hotelId) {
        ExecutorService executorService = new ThreadPoolExecutor(6, Integer.MAX_VALUE, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>());
        log.info("============酒店id为{}开始进行进行数据推送======", hotelId);
        //获取酒店的售卖房型id
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectHotelRoomId(hotelId);
        log.info("============酒店id为{}的售卖房型长度为{}=====", hotelId, switchCreateRoomEntities.size());
        List<Future<List<RoomDataEntityVo>>> futureList = new ArrayList<>();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
            if (!executorService.isShutdown()) {
                Future<List<RoomDataEntityVo>> future = executorService.submit(new MtHotelOrderChekck(switchCreateRoomEntity, "Thread" + hotelId));
                futureList.add(future);
            }
        }
        //关闭线程池，等线程后台执行
        executorService.shutdown();
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        Result<Map<String, String>> result;
        String msg = "";
        while (true) {
            if (executorService.isTerminated()) {
                for (Future<List<RoomDataEntityVo>> future : futureList) {
                    roomDataEntityVos.addAll(future.get());
                    log.info("=============线程返回的数据为{}", JSON.toJSONString(future.get()));
                    log.info("=============hotelId{}roomDataEntityVos添加完成了,长度为{},返回的数据为{}", hotelId, roomDataEntityVos.size(), future.get().size());
                }
                log.info("执行完毕,roomDataEntityVos的长度为{}", roomDataEntityVos.size());
                BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
                batchPushRoomVo.setHotelId(hotelId);
                batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos);
                if (roomDataEntityVos.size() > 0) {
                    log.info("============hotel的id为{}请求的json数据为{}=======", hotelId, JSON.toJSONString(batchPushRoomVo));
                    result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                    log.info("====================请求推送价格房态的接口返回的信息为{}============", result.getMsg());
                    msg = result.getMsg().toString();
                } else {
                    log.info("=======~~~~~~~~hotelId为{}数据为空~~~~~~无法调用携程推送价格房态接口================", hotelId);
                    msg = "没有调用接口";
                }
                break;
            }
        }
        List<Integer> liste = new ArrayList<>();
        liste.add(hotelId);
        log.info("============酒店id为{}执行完毕=====", hotelId);
        return new Result<>(msg);
    }

    /**
     * 多线程执行上架
     */
    class switchHotelUp implements Callable<Result<Object>> {
        Integer hotelId;
        String theadName;

        public switchHotelUp(Integer hotelId, String theadName) {
            this.hotelId = hotelId;
            this.theadName = theadName;
        }

        @Override
        public Result<Object> call() throws Exception {
            log.info("=============酒店id为{}开始调用pushRoomPriceAndStatus接口", this.hotelId);
            Result<Object> result = pushRoomPriceAndStatus(this.hotelId);
            log.info("=============酒店id为{}调用pushRoomPriceAndStatus接口结束", this.hotelId);
            return result;
        }
    }

    /**
     * 多线程调用下单前效验
     */
    class MtHotelOrderChekck implements Callable<List<RoomDataEntityVo>> {
        SwitchCreateRoomEntity switchCreateRoomEntity;
        String theadName;

        public MtHotelOrderChekck(SwitchCreateRoomEntity switchCreateRoomEntity, String theadName) {
            this.switchCreateRoomEntity = switchCreateRoomEntity;
            this.theadName = theadName;
        }

        @Override
        public List<RoomDataEntityVo> call() {
            List<RoomDataEntityVo> roomDataEntityVos = callMtCheckAssembleData(this.switchCreateRoomEntity);
            log.info("{}执行完毕,返回的数据为{}", theadName, JSON.toJSONString(roomDataEntityVos));
            return roomDataEntityVos;
        }
    }

    /**
     * @author: lmf
     * @time: 2020/10/13 15:33
     * 调用美团的下单前效验接口
     */
    public List<RoomDataEntityVo> callMtCheckAssembleData(SwitchCreateRoomEntity switchCreateRoomEntity) {
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.ORDER_CHECK.getUrl();
        map.put("hotelId", switchCreateRoomEntity.getMtHotelId());
        map.put("goodsId", switchCreateRoomEntity.getMtGoodId());
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        Date date = new Date();
        String now = formatter.format(date);
//        String startTimes= DateUtil.getNextDay(now);
        map.put("checkinDate", now);
        map.put("checkoutDate", DateUtil.getNextDay(now));
        map.put("roomNum", 1);
        map.put("totalPrice", 10000);
        long startTime = System.currentTimeMillis();
        MtOrderCheckVo mtOrderCheckVo = switchRestTempaleUtilsService.orderCheck(url, map);
        long endTime = System.currentTimeMillis();
        log.info("=============调用美团的下单前效验接口耗费时间为{}", (endTime - startTime));
        //携程
        RoomDataEntityVo roomDataEntityVo = new RoomDataEntityVo();
        roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        roomDataEntityVo.setStartDate(now);
        roomDataEntityVo.setEndDate(now);
        //去哪儿
        RoomDataEntityVo qunarRoomDataEntityVo = new RoomDataEntityVo();
        qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //b2b
        RoomDataEntityVo b2bRoomDataEntityVo = new RoomDataEntityVo();
        b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //channel
        RoomDataEntityVo channelRoomDataEntityVo = new RoomDataEntityVo();
        channelRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        String channelChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_CHANNEL_A.getName());
        //房态推送数据
        //库存推送数据
        if (mtOrderCheckVo.getCode() == MtHotelOrderCheckCodeEnums.SUCESS.getCode()) {
            List<PirceModelVo> pirceModelVos = mtOrderCheckVo.getPriceModels();
            //携程房价实体
            RoomPriceModelVo roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setCurrency("CNY");
            roomPriceModelVo.setChannel(channel);
            //去哪儿房价实体
            RoomPriceModelVo qunarModelVo = new RoomPriceModelVo();
            qunarModelVo.setCurrency("CNY");
            qunarModelVo.setChannel(QunarChannel);
            //b2b房价实体
            RoomPriceModelVo b2bModelVo = new RoomPriceModelVo();
            b2bModelVo.setCurrency("CNY");
            b2bModelVo.setChannel(b2bChannel);
            //channel房价实体
            RoomPriceModelVo channelModelVo = new RoomPriceModelVo();
            channelModelVo.setCurrency("CNY");
            channelModelVo.setChannel(channelChannel);
            for (PirceModelVo pirceModelVo : pirceModelVos) {
                //价格推送数据
                startTime = System.currentTimeMillis();
                log.info("=================获取酒店上架价格配置start===================");
                Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = switchPushRoomService.getOnlinePriceSet();
                endTime = System.currentTimeMillis();
                log.info("=================获取酒店上架价格配置end,耗费时间为{}===================", (endTime - startTime));
                //针对统一的进行价格公式计算
                Map<String, Object> priceMap = new HashMap<>();
                //判断是否参加促销活动
                startTime = System.currentTimeMillis();
                SwitchHotelActiveTagEntity switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), pirceModelVo.getDate());
                if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                    priceMap = switchPushRoomService.getPriceV2(priceSetMap, pirceModelVo.getSalePrice(), pirceModelVo.getSubPrice(), null);
                } else {
                    String currentWeekDay = DateUtil.dayForWeek(pirceModelVo.getDate());
                    //促销
                    if (switchHotelActiveTagEntity.getWeek().contains("每天") || switchHotelActiveTagEntity.getWeek().contains(currentWeekDay)) {
                        priceMap = switchPushRoomService.getPriceV2(priceSetMap, pirceModelVo.getSalePrice(), pirceModelVo.getSubPrice(), switchHotelActiveTagEntity);
                    } else {//判断当前周几，是否符合促销活动
                        priceMap = switchPushRoomService.getPriceV2(priceSetMap, pirceModelVo.getSalePrice(), pirceModelVo.getSubPrice(), null);
                    }
                }
                endTime = System.currentTimeMillis();
                log.info("==========计算价格公式所耗费时间为{}", (endTime - startTime));
                //如果价格符合公式，房态可预定 有库存就进行设置推送
                double price = Double.parseDouble(priceMap.get("ctripPrice").toString());
                double channelPrice = Double.parseDouble(priceMap.get("qunarPrice").toString());
                roomPriceModelVo.setRoomPrice(price);
                qunarModelVo.setRoomPrice(channelPrice);
                b2bModelVo.setRoomPrice(channelPrice);
                channelModelVo.setRoomPrice(channelPrice);
                roomDataEntityVo.setStartDate(pirceModelVo.getDate());
                roomDataEntityVo.setEndDate(pirceModelVo.getDate());
                roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
                qunarRoomDataEntityVo.setStartDate(pirceModelVo.getDate());
                qunarRoomDataEntityVo.setEndDate(pirceModelVo.getDate());
                qunarRoomDataEntityVo.setRoomPriceModel(qunarModelVo);
                b2bRoomDataEntityVo.setStartDate(pirceModelVo.getDate());
                b2bRoomDataEntityVo.setEndDate(pirceModelVo.getDate());
                b2bRoomDataEntityVo.setRoomPriceModel(b2bModelVo);
                channelRoomDataEntityVo.setStartDate(pirceModelVo.getDate());
                channelRoomDataEntityVo.setEndDate(pirceModelVo.getDate());
                channelRoomDataEntityVo.setRoomPriceModel(channelModelVo);
                //携程房态推送实体
                RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
                roomStatusModelVo.setChannel(channel);
                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                //去哪儿房态
                RoomStatusModelVo qunarRoomStatusModelVo = new RoomStatusModelVo();
                qunarRoomStatusModelVo.setChannel(QunarChannel);
                qunarRoomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                qunarRoomDataEntityVo.setRoomStatusModel(qunarRoomStatusModelVo);
                //b2b房态
                RoomStatusModelVo b2bRoomStatusModelVo = new RoomStatusModelVo();
                b2bRoomStatusModelVo.setChannel(b2bChannel);
                b2bRoomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                b2bRoomDataEntityVo.setRoomStatusModel(b2bRoomStatusModelVo);
                //channels
                RoomStatusModelVo channleRoomStatusModelVo = new RoomStatusModelVo();
                channleRoomStatusModelVo.setChannel(channelChannel);
                channleRoomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                channelRoomDataEntityVo.setRoomStatusModel(b2bRoomStatusModelVo);

                //库存推送实体
                RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(channel);
                roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPreservedQuantity(0);
                roomInventoryModelVo.setUnPreservedQuantity(1);
                roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                roomDataEntityVos.add(roomDataEntityVo);
                roomDataEntityVos.add(qunarRoomDataEntityVo);
                roomDataEntityVos.add(b2bRoomDataEntityVo);
                roomDataEntityVos.add(channelRoomDataEntityVo);
            }
        } else {
            //房态推送实体
            RoomStatusModelVo roomStatusModelVo = new RoomStatusModelVo();
            roomStatusModelVo.setChannel(channel);
            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
            roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
            //库存推送实体
            RoomInventoryModelVo roomInventoryModelVo = new RoomInventoryModelVo();
            roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
            roomInventoryModelVo.setChannel(channel);
            roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
            roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
            roomInventoryModelVo.setPreservedQuantity(0);
            roomInventoryModelVo.setUnPreservedQuantity(1);
            roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
            roomDataEntityVos.add(roomDataEntityVo);
        }
        log.info("结果数据为{}", roomDataEntityVos.size());
        return roomDataEntityVos;
    }

    /***
     * @Author: lmf
     * @Date: 2020/10/6
     * 推送价格房态
     */
    public void pushData(Integer hotelId) {
//        //先调用爬虫,爬取房态如果失败就手动去拉
//        String url = CommonUrlConstants.SPIDER_HOST + "/meituanSpider/meituanSpiderHotelGoodsNoticeByMtHotelRoom";
//        Map<String, List<String>> map = new HashMap<>();
//        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(hotelId);
//        List<String> list = new ArrayList<>();
//        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
//            list.add(String.valueOf(switchCreateRoomEntity.getMtGoodId()));
//            map.put(String.valueOf(switchCreateRoomEntity.getMtHotelId()), list);
//            try {
//                Thread.sleep(6000);
//                Result result1 = switchPushRoomService.retryPushRoomData(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), 1);
//                if (result1.getCode() == CommonConstants.SUCCESS) {
//                    Result result = RestTemplateUtils.post(url, JacksonUtil.objectToJson(map), restTemplate);
//                    //如果调用爬虫接口失败,重新调用
//                    if (result.getCode() == CommonConstants.ERROR) {
//                        //如果调用爬虫接口失败,重新调用
//                        RestTemplateUtils.post(url, JacksonUtil.objectToJson(map), restTemplate);
//                    }
//                }
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        }
    }

    class PushTRoomhread implements Runnable {
        private Integer hotelId;

        public PushTRoomhread(Integer hotelId) {
            this.hotelId = hotelId;
        }

        @Override
        public void run() {
            pushData(hotelId);
        }
    }

    class PushThread implements Runnable {
        private List<Integer> id;
        private int status;

        public PushThread(List<Integer> id, int status) {
            this.id = id;
            this.status = status;
        }

        @Override
        public void run() {
            saveRedisCache(status);
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/24
     */
    public void saveRedisCache(int status) {
        log.info("==============酒店的状态{}==================", status);
        //上线售卖
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = new ArrayList<>();
        if (status == 1) {
            switchCreateRoomEntities = switchCreateRoomMapper.selectHotelUpStatus(3);
            for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                //清除与售卖房型的关联数据
                String key = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //添加美团酒店id+美团产品id的key
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                redisService.set(key, switchCreateRoomEntity.getMtRoomId());
                //添加美团酒店id+美团房型id
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
                redisService.set(key, "1");
                //添加美团酒店id+美团产品id+餐食
                if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")) {
                    redisService.set(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + "_0", 0);
                } else if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("640292")) {
                    redisService.set(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + "_1", 2);
                } else {
                    redisService.set(CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + "_1", switchCreateRoomEntity.getMealCount());
                }
            }
        } else {
            switchCreateRoomEntities = switchCreateRoomMapper.selectHotelUpStatus(2);
            for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                //清除与售卖房型的关联数据
                String key = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //清除美团酒店id+美团产品id的key
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //清除美团酒店id+美团房型id
                key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                //清除美团酒店id+美团产品id+餐食
                key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_0";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
            }
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 修改酒店上下线状态
     */
    @Override
    public Result<Object> modifyHotelStatus(SetHotelUpVo setHotelUpVo) {
        int status = 1;
        if (setHotelUpVo.getStatus() == 0 ) {
            status = 0;
        }else if(setHotelUpVo.getStatus()==1){
            status=2;
        }

        Integer[] ids = new Integer[]{setHotelUpVo.getHotelId()};
        Result<Object> result;
        //黑名单的话直接下架
        if (setHotelUpVo.getStatus() == 2) {
            //saveRedisCache(0);
            result = pushHotelStatusByBlack(ids);
        } else {
            result = pushHotelStatus(ids, status);
        }
        List<Integer> list = new ArrayList<>();
        list.add(setHotelUpVo.getHotelId());
        if (result.getCode() == CommonConstants.SUCCESS) {
            int flag = switchHotelUpMapper.updateHotelSaleStatus(setHotelUpVo.getHotelId(), (setHotelUpVo.getStatus()==0)?4:setHotelUpVo.getStatus());
            //如果是上架就调用下单前效验
            if (status == 1) {
                pushRoomPriceAndStatus(setHotelUpVo.getHotelId());
                Integer mtHotelId = switchHotelUpMapper.selectMtHotelIdByHotelId(setHotelUpVo.getHotelId());
                if (!ObjectUtils.isEmpty(mtHotelId)) {
                    Integer[] hotelId = new Integer[1];
                    hotelId[0] = mtHotelId;
                    String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_HOTEL_FAILURE.getUrl();
                    Map<String, Object> params = new HashMap<>();
                    params.put("hotelIds", hotelId);
                    Result<List<MtHotelDownVo>> result2 = switchRestTempaleUtilsService.sendReuestToMtCheckHotelFailure(url, params);
                    List<MtHotelDownVo> mtHotelDownVos = result2.getData();
                    //调用美团接口检查是否有被拉入黑名单的酒店
                    if (mtHotelDownVos.size() < 1) {
                        checkHotelGoodStatus(setHotelUpVo.getHotelId());
                    } else {
                        for (MtHotelDownVo mtHotelDownVo : mtHotelDownVos) {
                            //0 下线  1 上线
                            if (mtHotelDownVo.getStatus() == 0) {
                                switchHotelUpMapper.updateHotelStatis(String.valueOf(setHotelUpVo.getHotelId()), 0);
                            }
                            checkHotelGoodStatus(setHotelUpVo.getHotelId());
                        }
                    }
                    //设置缓存
                    //saveRedisCache(status);
                }
                //添加操作日志
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(1);
                switchHotelUpLogEntity.setHotelId(setHotelUpVo.getHotelId());
                switchHotelUpLogEntity.setUp(setHotelUpVo.getStatus());
                switchHotelUpLogEntity.setUsername("admin-后台操作");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
            } else {
                //添加操作日志
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(1);
                switchHotelUpLogEntity.setHotelId(setHotelUpVo.getHotelId());
                switchHotelUpLogEntity.setUp(setHotelUpVo.getStatus());
                switchHotelUpLogEntity.setUsername("admin-后台操作");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
            }
            if (flag > 0) {
                return new Result<>(CommonConstants.SUCCESS, "操作成功");
            } else {
                return new Result<>("操作失败");
            }
        } else {
            return new Result<>("操作失败");
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 获取上架所有数据
     * @param getRoomListVo
     */
    @Override
    public Result<Object> getHotelList(GetRoomListVo getRoomListVo) {
        PageHelper.startPage(getRoomListVo.getPageCode(), getRoomListVo.getPageSize());
        List<SwitchHotelUpEntity> list = switchHotelUpMapper.selectByHotelName(getRoomListVo.getHotelName());
        PageInfo<SwitchHotelUpEntity> pageInfo = new PageInfo<>(list);
        return new Result<>(pageInfo);
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 导入execel到数据库中
     */
    @Override
    public Result<Object> upExecel(MultipartFile excelFile) {
        List<SwitchHotelUpEntity> switchHotelUpEntities = new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            tab:
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(0);
                cell.setCellType(CellType.STRING);
                cell = sheetRow.getCell(0);
                String hotelName = cell.getStringCellValue();
                cell = sheetRow.getCell(1);
                Double masterHotelId = cell.getNumericCellValue();
                cell = sheetRow.getCell(2);
                Double hotelId = cell.getNumericCellValue();
                SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectByHotelId(hotelId.intValue());
                if (!ObjectUtil.isEmpty(switchHotelUpEntity)) {
                    continue tab;
                }
                switchHotelUpEntity = new SwitchHotelUpEntity();
                switchHotelUpEntity.setId(StringUtil.getUUID());
                switchHotelUpEntity.setHotelId(hotelId.intValue());
                switchHotelUpEntity.setHotelName(hotelName);
                switchHotelUpEntity.setUp(0);
                switchHotelUpEntity.setCreateTime(new Date());
                switchHotelUpEntity.setRemark("");
                switchHotelUpEntity.setMasterHotelId(masterHotelId.intValue());
                switchHotelUpEntities.add(switchHotelUpEntity);
            }
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        if (switchHotelUpEntities.size() > 0) {
            int result = switchHotelUpMapper.insertList(switchHotelUpEntities);
            if (result > 0) {
                return new Result<>();
            } else {
                return new Result<>("导入失败");
            }
        } else {
            return new Result<>("导入失败");
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/30
     * 上下线酒店缓存
     */
    @Override
    public Result<Object> cacheOperator(SetHotelUpVo setHotelUpVo) {
        log.info("===========缓存的状态为{}", setHotelUpVo.getStatus());
        List<SwitchCreateRoomEntity> switchCreateRoomEntities;
        if (setHotelUpVo.getStatus() == 1) {
            switchCreateRoomEntities = switchCreateRoomMapper.selectUpHotelRoomIds();
        } else {
            switchCreateRoomEntities = switchCreateRoomMapper.selectNoUpHotelRoomIds();
        }
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            //停售
            if (setHotelUpVo.getStatus() != 1) {
                redisService.remove(key);
            } else {//在售
                redisService.set(key, switchCreateRoomEntity.getMtRoomId());
            }
        }
        return new Result<>();
    }

    @Override
    public Result<Object> getUpHotelAsc() {
        List<Integer> list = switchHotelUpMapper.getUpHotelAsc();
        return new Result<>(GsonUtils.GsonString(list), "success");
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 设置酒店的售卖状态  携程关闭各渠道在售
     */
    public Result<Object> pushHotelStatus(Integer[] hotelIds, int status) {
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", hotelIds);
        if(status==2){
            updateChannelVoMap.put("cBookable", 0);
        }else{
            updateChannelVoMap.put("cBookable", status);
        }
        if(status==0){
            updateChannelVoMap.put("qBookable", 0);
            updateChannelVoMap.put("channelABookable", 0);
            updateChannelVoMap.put("b2bBookable", 0);
        }else{
            updateChannelVoMap.put("qBookable", 1);
            updateChannelVoMap.put("channelABookable", 1);
            updateChannelVoMap.put("b2bBookable", 1);
        }
        return switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
    }

    /***
     * @Author: lmf
     * @Date: 2020/9/23
     * 设置酒店各渠道统一上下线
     */
    public Result<Object> setHotelStatus(Integer[] hotelIds, int status) {
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", hotelIds);
        updateChannelVoMap.put("cBookable", status);
        updateChannelVoMap.put("qBookable", status);
        updateChannelVoMap.put("channelABookable", status);
        updateChannelVoMap.put("b2bBookable", status);
        return switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
    }

    /**
     * @author: lmf
     * @time: 2020/11/6 10:03
     * 设置酒店房型推送 针对黑名单的直接下架
     */
    public Result<Object> pushHotelStatusByBlack(Integer[] hotelIds) {
        Map<String, Object> updateChannelVoMap = new HashMap<>();
        updateChannelVoMap.put("hotelIDs", hotelIds);
        updateChannelVoMap.put("cBookable", 0);
        updateChannelVoMap.put("qBookable", 0);
        updateChannelVoMap.put("channelABookable", 0);
        updateChannelVoMap.put("b2bBookable", 0);
        return switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
    }

    /**
     * @Description: 设置携程-美团酒店商品对应缓存
     * @return: boolean
     * @Author: Zhang·jz
     * @date: 2020/10/21
     */
    @Override
    public Result<Boolean> setRedisByUpHotelGoodsId() {
        boolean ret = false;
        int count = 0;
        //获取所有携程，美团酒店房型相关id
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAllHotelRoomId();
        if (!switchCreateRoomEntities.isEmpty() && switchCreateRoomEntities.size() > 0) {
//            switchCreateRoomEntities.forEach(switchCreateRoomEntity -> {
            for (int i = 0; i < switchCreateRoomEntities.size(); i++) {
                SwitchCreateRoomEntity switchCreateRoomEntity = switchCreateRoomEntities.get(i);
                Map map = new HashMap();
                map.put("switchHotelId", switchCreateRoomEntity.getHotelId());
                map.put("switchMasterHotelId", switchCreateRoomEntity.getMasterHotelId());
                map.put("switchRoomId", switchCreateRoomEntity.getRoomId());
                map.put("mtRoomId", switchCreateRoomEntity.getMtRoomId());

                //通过美团酒店+产品，获取携程相关数据
                String mtHotelGoodsKey = CommonConstants.SWITCH_SELLING_REDIS_BY_MT + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                log.info("mtHotelGoodsKey>>>{}", mtHotelGoodsKey);
                //选择redis db 2 为存储数据表
                boolean retSetRedis = redisService.set(CommonBaseConstants.REDIS_DB_2, mtHotelGoodsKey, map);
                if (retSetRedis) {
                    count++;
                }
            }
            if (switchCreateRoomEntities.size() == count) {
                ret = true;
            }
        }

        return new Result<>(ret);
    }

    /**
     * @Description: 清除携程-美团酒店商品对应缓存
     * @return: boolean
     * @Author: Zhang·jz
     * @date: 2020/10/21
     */
    @Override
    public Result<Boolean> delRedisByUpHotelGoodsId() {
        //获取所有携程，美团酒店房型相关id
        String keys = "*switch_selling_redis_by_mt_*";
        Set<String> keysList = stringRedisTemplate.keys(keys);
        keysList.forEach(key -> {
            key = key.substring(key.indexOf(CommonConstants.SWITCH_SELLING_REDIS_BY_MT), key.length());

            log.info("key>>>{}", key);
            //选择redis db 2 为存储数据表
            redisService.remove(CommonBaseConstants.REDIS_DB_2, key);
        });
        return new Result<>(true);
    }

    /**
     * @author: lmf
     * @time: 2020/10/27 16:39
     * 导入酒店数据,开启酒店售卖
     */
    @SneakyThrows
    @Override
    public Result<Object> submitUploadSale(MultipartFile excelFile, Integer status) {
        List<Integer> can = new ArrayList<>();
        List<Integer> black = new ArrayList<>();
        try {
            Workbook workbook = WorkbookFactory.create(excelFile.getInputStream());
            excelFile.getInputStream().close();
            //工作表对象
            Sheet sheet = workbook.getSheetAt(0);
            for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
                Row sheetRow = sheet.getRow(i);
                Cell cell = sheetRow.getCell(1);
                Double hotelId = cell.getNumericCellValue();
                log.info("=======共有表格数据长度为{}===", sheet.getPhysicalNumberOfRows());
                Example example = new Example(SwitchHotelUpEntity.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("hotelId", hotelId.intValue());
                //黑名单的酒店不进行创建,不存在上架表的不创建
                SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectOneByExample(example);
                log.info("=====switchHotelUpEntity的值为{}",switchHotelUpEntity.toString());
                if (switchHotelUpEntity.getUp() != 2&&switchHotelUpEntity.getUp() != 0&&switchHotelUpEntity.getStatus()!=2) {
                    can.add(hotelId.intValue());
                    ExecutorService executorService = Executors.newFixedThreadPool(1);
                    executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                    executorService.shutdown();
                    Thread.sleep(300);
                } else if (switchHotelUpEntity.getUp() == 2) {
                    black.add(hotelId.intValue());
                }else if(switchHotelUpEntity.getUp() == 0){
                    SwitchHotelUpLogEntity switchHotelUpLogEntity=new SwitchHotelUpLogEntity();
                    switchHotelUpLogEntity.setUp(0);
                    switchHotelUpLogEntity.setHotelId(hotelId.intValue());
                    switchHotelUpLogEntity.setUsername("admin批量导入-酒店下线");
                    switchHotelUpLogEntity.setCreateTime(new Date());
                    switchHotelUpLogEntity.setGenre(1);
                    switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                    if(switchHotelUpEntity.getStatus()!=4){
                        switchHotelUpEntity=new SwitchHotelUpEntity();
                        switchHotelUpEntity.setStatus(3);
                        switchHotelUpMapper.updateByExampleSelective(switchHotelUpEntity,example);
                    }
                }

            }
            log.info("========上架前可循环一次所有上架酒店,目前有{}个酒店====", can.size());
        } catch (InvalidFormatException | IOException e) {
            e.printStackTrace();
        }
        log.info("========上架前可循环一次所有上架酒店,目前有{}个酒店====", can.size());
        ExecutorService executorService = Executors.newFixedThreadPool(1);
        executorService.submit(new submitSaleThread(can, black));
        executorService.shutdown();

        return new Result<>();

    }

    class submitSaleThread implements Runnable {
        List<Integer> can;
        List<Integer> black;

        public submitSaleThread(List<Integer> can, List<Integer> black) {
            this.can = can;
            this.black = black;
        }

        @Override
        public void run() {

   /*         tab:for(SwitchHotelUpVo switchHotelUpVo:switchHotelUpVos){
                Example example=new Example(SwitchHotelUpEntity.class);
                Example.Criteria criteria=example.createCriteria();
                criteria.andEqualTo("hotelId",switchHotelUpVo.getHotelId());
                //黑名单的酒店不进行创建
                SwitchHotelUpEntity switchHotelUpEntity=switchHotelUpMapper.selectOneByExample(example);
                if(ObjectUtil.isEmpty(switchHotelUpEntity)||switchHotelUpEntity.getUp()==2){
                    continue tab;
                }else{
                    Integer[] hotelId = new Integer[1];
                    hotelId[0]=switchHotelUpVo.getMtHotelId();
                    //调用美团接口检查是否有被拉入黑名单的酒店
                    String url = CommonUrlConstants.MEITUAN_HOST + MtRequestUrlEnums.CHECK_HOTEL_FAILURE.getUrl();
                    Map<String, Object> params = new HashMap<>();
                    params.put("hotelIds", hotelId);
                    Result<List<MtHotelDownVo>> result = switchRestTempaleUtilsService.sendReuestToMtCheckHotelFailure(url, params);
                    List<MtHotelDownVo> mtHotelDownVos = result.getData();
                    //说明酒店是正常的
                    if(mtHotelDownVos.size()<1){
                        can.add(switchHotelUpVo.getHotelId());
                        checkHotelGoodStatus(switchHotelUpVo.getHotelId());
                    }else{
                        for (MtHotelDownVo mtHotelDownVo : mtHotelDownVos) {
                            //0 下线  1 上线
                            if (mtHotelDownVo.getStatus() == 0) {
                                switchHotelUpMapper.updateHotelStatis(String.valueOf(switchHotelUpVo.getHotelId()), 0);
                                Map<String, Object> updateChannelVoMap = new HashMap<>();
                                updateChannelVoMap.put("hotelIDs", new int[]{switchHotelUpVo.getHotelId()});
                                updateChannelVoMap.put("cBookable", 0);
                                updateChannelVoMap.put("qBookable", 1);
                                updateChannelVoMap.put("channelABookable", 1);
                                updateChannelVoMap.put("b2bBookable", 1);
                                switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                            } else {
                                can.add(switchHotelUpVo.getHotelId());
                            }
                            checkHotelGoodStatus(switchHotelUpVo.getHotelId());
                        }
                    }
                }
            }*/
            List<List<Integer>> canHotelIds = ListUtils.parititon(can, 50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities = new ArrayList<>();
            if (canHotelIds.size() > 0) {
                for (List<Integer> list : canHotelIds) {
                    Integer[] hotelId = new Integer[list.size()];
                    Result<Object> result1 = pushHotelStatus(list.toArray(hotelId), 1);
                    if (result1.getCode() == CommonConstants.SUCCESS) {
                        switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","), 3);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(3);
                            switchHotelUpLogEntity.setUsername("admin-批量导入售卖");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                    }else if(result1.getMsg().toString().contains("频率")){
                        try {
                            Thread.sleep(6000);
                            result1=pushHotelStatus(list.toArray(hotelId), 1);
                            switchHotelUpMapper.updateHotelSale(StringUtils.join(list, ","), 3);
                            SwitchHotelUpLogEntity switchHotelUpLogEntity;
                            for (Integer id : list) {
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(id);
                                switchHotelUpLogEntity.setUp(3);
                                switchHotelUpLogEntity.setUsername("admin-批量导入售卖"+result1.getMsg());
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    try {
                        Thread.sleep(8000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
            if (switchHotelUpLogEntities.size() > 0) {
                switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                saveRedisCache(1);
            }
            if (black.size() > 1) {
                List<List<Integer>> blackHotelIds = ListUtils.parititon(black, 50);
                if (canHotelIds.size() > 0) {
                    for (List<Integer> list : blackHotelIds) {
                        Integer[] hotelId = new Integer[list.size()];
                        //保存缓存
                        //saveRedisCache(list, 1);
                        Map<String, Object> updateChannelVoMap = new HashMap<>();
                        updateChannelVoMap.put("hotelIDs", hotelId);
                        updateChannelVoMap.put("cBookable", 0);
                        updateChannelVoMap.put("qBookable", 0);
                        updateChannelVoMap.put("channelABookable", 0);
                        updateChannelVoMap.put("b2bBookable", 0);
                        Result<Object> result=switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                        if(result.getMsg().toString().contains("执行频率过快")){
                            try {
                                Thread.sleep(2000);
                                switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                        }
                        SwitchHotelUpLogEntity switchHotelUpLogEntity;
                        for (Integer id : list) {
                            switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                            switchHotelUpLogEntity.setCreateTime(new Date());
                            switchHotelUpLogEntity.setGenre(1);
                            switchHotelUpLogEntity.setHotelId(id);
                            switchHotelUpLogEntity.setUp(2);
                            switchHotelUpLogEntity.setUsername("admin-批量导入售卖-记录黑名单");
                            switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        }
                        try {
                            Thread.sleep(8000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
           /* if(redisService.exists("every_week_reset_up_hotel_data")) {
                Example example = new Example(SwitchHotelUpEntity.class);
                Example.Criteria criteria = example.createCriteria();
                criteria.andEqualTo("up", 1);
                List<SwitchHotelUpEntity> switchHotelUpEntities = switchHotelUpMapper.selectByExample(example);
                List<Integer> down = new ArrayList<>();
                for (SwitchHotelUpEntity switchHotelUpEntity : switchHotelUpEntities) {
                    down.add(switchHotelUpEntity.getHotelId());
                }
                List<List<Integer>> downcHotelIds = ListUtils.parititon(down, 50);
                if (canHotelIds.size() > 0) {
                    for (List<Integer> list : downcHotelIds) {
                        Integer[] hotelId = new Integer[list.size()];
                        pushHotelStatus(list.toArray(hotelId), 0);
                        try {
                            Thread.sleep(6000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }*/
        }
    }

    @Override
    public Result<Object> getUpHotelGoodsDataForBasicRoom() {
        List<SwitchCreateRoomDto> list = null;
        if (null != redisService.get(MeituanConstants.REDIS_BASIC_SOME_HOTELS_TEST)) {
            Map map = new HashMap();
            map.put("mtHotelId", redisService.get(MeituanConstants.REDIS_BASIC_SOME_HOTELS_TEST));
            list = switchHotelUpMapper.getUpHotelGoodsDataByMap(map);
        } else {
            list = switchHotelUpMapper.getUpHotelGoodsData();
        }
        return new Result(GsonUtils.GsonString(list), "success");
    }


    @Override
    public Result<Object> getUpHotelGoodsData() {
        List<SwitchCreateRoomDto> list = switchHotelUpMapper.getUpHotelGoodsData();
        return new Result(GsonUtils.GsonString(list), "success");
    }

    @Override
    public Result<Object> getUpHotelGoodsDataByHotelId(Integer mtHotelId) {
        Map map = new HashMap();
        map.put("mtHotelId", mtHotelId);
        List<SwitchCreateRoomDto> list = switchHotelUpMapper.getUpHotelGoodsDataByHotelId(map);
        return new Result(GsonUtils.GsonString(list), "success");
    }

    /**
     * 删除缓存和下线错误的产品id
     *
     * @return
     */
    @Override
    public Result<Object> delErrorRomId() {
        return null;
    }

    @Override
    public Result<List<CompareRoomForFpVO>> getUpHotelGoodsDataFp() {
        List<CompareRoomForFpVO> roomList = switchHotelUpMapper.getUpHotelGoodsDataFp();
        return new Result<>(roomList);
    }

    /**
     * 添加所有酒店的缓存
     *
     * @return
     */
    @Override
    public Result<Object> addHotel() {
        List<SwitchCreateSubHotelEntity> switchCreateSubHotelEntities = switchCreateSubHotelMapper.selectAll();
        for (SwitchCreateSubHotelEntity switchCreateSubHotelEntity : switchCreateSubHotelEntities) {
            //先获取美团的id
            String mtHotelId = "";
            Map<String, String> params = new HashMap<>();
            params.put("masterHotelId", String.valueOf(switchCreateSubHotelEntity.getMasterHotelId()));
            String url = CommonUrlConstants.COMPARE_HOST + "/" + CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
            Result result;
            try {
                result = switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url, params);
                if (result.getCode() == CommonConstants.SUCCESS) {
                    mtHotelId = result.getData().toString();
                    log.info("==========美团的酒店id为============{}", mtHotelId);
                    redisService.set(MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS + mtHotelId, 1);
                }
            } catch (Exception e) {
                log.info("=======获取美团酒店id出现异常==============");
            }
        }
        List<SwitchHotelUpEntity> switchHotelUps = switchHotelUpMapper.selectAll();
        for (SwitchHotelUpEntity switchHotelUpEntity : switchHotelUps) {
            //先获取美团的id
            String mtHotelId = "";
            Map<String, String> params = new HashMap<>();
            params.put("masterHotelId", String.valueOf(switchHotelUpEntity.getMasterHotelId()));
            String url = CommonUrlConstants.COMPARE_HOST + "/" + CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
            Result result;
            try {
                result = switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url, params);
                if (result.getCode() == CommonConstants.SUCCESS) {
                    mtHotelId = result.getData().toString();
                    log.info("==========美团的酒店id为============{}", mtHotelId);
                    redisService.set(MeituanConstants.REIDS_MAP_ALL_SALE_HOTEL_IDS + mtHotelId, 1);
                }
            } catch (Exception e) {
                log.info("=======获取美团酒店id出现异常==============");
            }
        }
        return null;
    }

    /**
     * 添加美团的房型到缓存中key:mt_hotel_id+mt_room_id 作为效验房型是否失效的凭证
     *
     * @return
     */
    @Override
    public Result<Object> addHotelRoomCache() {
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
            redisService.set(key, "1");
        }
        return new Result<>();
    }

    /**
     * 添加美团的房型到缓存中key:mt_hotel_id+mt_good_id+餐食 作为效验餐食是否失效的凭证
     *
     * @return
     */
    @Override
    public Result<Object> addHotelGoodBreakfastCache() {
        List<SwitchCreateRoomFailureEntity> switchCreateRoomFailureEntities = switchCreateRoomFailureMapper.selectAll();
        for (SwitchCreateRoomFailureEntity switchCreateRoomEntity : switchCreateRoomFailureEntities) {
            String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
            if (redisService.exists(key)) {
                redisService.remove(key);
            }
            String key2 = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_0";
            if (redisService.exists(key2)) {
                redisService.remove(key2);
            }
        }
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")) {
                String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_0";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                String key2 = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_0";
                redisService.set(key2, 0);
            } else if (switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("640292")) {
                String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                String key2 = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                redisService.set(key2, 2);
            } else {
                String key = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId() + "_1";
                if (redisService.exists(key)) {
                    redisService.remove(key);
                }
                String key2 = CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId() + "_1";
                redisService.set(key2, switchCreateRoomEntity.getMealCount());
            }
        }
        return new Result<>();
    }

    public Result<Object> addHotelGoodCache() {
        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectAll();
        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
        }
        return new Result<>();
    }

    /**
     * 添加酒店相关的缓存
     *
     * @return
     */
    @Override
    public Result<Object> addAllCache(Integer genre) {
        if (genre == 4) {
            //4.美团酒店id+美团产品id+餐食类型,value:餐食数量
            addHotelGoodBreakfastCache();
        } else if (genre == 1) {
            redisService.remove("goods_query_job_up_hotel_data");
            //1.酒店缓存
            addHotel();
        } else if (genre == 2) {
            //2.美团酒店id+美团产品id,value:为美团房型id
            addHotelGoodCache();
        } else if (genre == 3) {
            //3.美团酒店id+美团房型id
            addHotelRoomCache();
        } else {
            //1.酒店缓存
            redisService.remove("goods_query_job_up_hotel_data");
            addHotel();
            //2.美团酒店id+美团产品id,value:为美团房型id
            addHotelGoodCache();
            //3.美团酒店id+美团房型id
            addHotelRoomCache();

            //4.美团酒店id+美团产品id+餐食类型,value:餐食数量
            addHotelGoodBreakfastCache();
        }
        return new Result<>();
    }

    /**
     * @author: lmf
     * @date: 2020/8/14 13:45
     * 设置携程酒店下线
     */
    @Override
    public Result<Object> downHotel(SetHotelOnlineVo setHotelOnlineVo) {
        log.info("====================美团的酒店上下线请求数据为{}===========", JSON.toJSONString(setHotelOnlineVo));
        //如果美团的酒店对应的携程暂时没有添加
        //先获取美团的id
        Integer hotelId = switchCreateRoomMapper.getHotelIdByMtHotelId(setHotelOnlineVo.getMtHotelId());
        if (ObjectUtils.isEmpty(hotelId)) {
            Map<String,String> params=new HashMap<>();
            params.put("mtHotelId", String.valueOf(setHotelOnlineVo.getMtHotelId()));
            String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_HOTEL_ID.getUrl();
            Result<Integer> result;
            try {
                result= switchRestTempaleUtilsService.sendPOstRequestByGetHotelId(url,params);
                if(result.getCode()==CommonConstants.SUCCESS){
                    hotelId=result.getData();
                    log.info("==========携程的酒店id为============{}",hotelId);
                }else{
                    log.debug("============asad美团的酒店id为{}，无对应的酒店数据", setHotelOnlineVo.getMtHotelId());
                    return new Result<>();
                }
            }catch (Exception e){
                log.debug("============asad美团的酒店id为{}，无对应的酒店数据", setHotelOnlineVo.getMtHotelId());
                return new Result<>();
            }
        }
        if (setHotelOnlineVo.getStatus() == 1) {
            //判断是否在黑名单里
            SwitchHotelUpEntity switchHotelUpEntity = switchHotelUpMapper.selectByHotelId(hotelId);
            //黑名单的酒店不自动开起来
            if (!ObjectUtil.isEmpty(switchHotelUpEntity) && switchHotelUpEntity.getUp() == 2||switchHotelUpEntity.getStatus()==2) {
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(2);
                switchHotelUpLogEntity.setHotelId(hotelId);
                switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                switchHotelUpLogEntity.setUsername("system-黑名单酒店仅记录不上线");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                return new Result<>();
            } else {
                if (ObjectUtils.isEmpty(hotelId)) {
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                    switchHotelUpLogEntity.setCreateTime(new Date());
                    switchHotelUpLogEntity.setGenre(2);
                    switchHotelUpLogEntity.setHotelId(setHotelOnlineVo.getMtHotelId());
                    switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                    switchHotelUpLogEntity.setUsername("system-美团酒店id对应酒店携程id无售卖房型/映射");
                    switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                    return new Result<>("开启上线成功");
                } else {
                    Map<String, Object> updateChannelVoMap = new HashMap<>();
                    updateChannelVoMap.put("hotelIDs", new int[]{hotelId});
                    int up=1;
                    if(switchHotelUpEntity.getStatus()==3){
                        up=3;
                        updateChannelVoMap.put("cBookable", setHotelOnlineVo.getStatus());
                    }else{
                        updateChannelVoMap.put("cBookable", 0);
                    }
                    updateChannelVoMap.put("qBookable", 5);
                    updateChannelVoMap.put("channelABookable",5);//默认停售
                    updateChannelVoMap.put("b2bBookable", 5);//默认停售
                    Result<Object> setHotelSupplierBookableResult = switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
                    if (setHotelSupplierBookableResult.getCode() == CommonConstants.SUCCESS) {
                        List<Integer> list = new ArrayList<>();
                        list.add(hotelId);
                        List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectById(list);
                        for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                            String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                            redisService.set(key, switchCreateRoomEntity.getMtRoomId());
                            String key2 = CommonConstants.SWITCH_SELLING_THE_HOUSE_ROOM_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtRoomId();
                            redisService.set(key2, 1);
                            //早餐缓存498160
                            if(switchCreateRoomEntity.getRateCodePropertyValueIdList().contains("498160")){
                                key2=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+ switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId()+"_0";
                                redisService.set(key2,0);
                            }else{
                                key2=CommonConstants.SWITCH_CREATE_ROOM_BREAKFAST+ switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId()+"_1";
                                redisService.set(key2,switchCreateRoomEntity.getMealCount());
                            }
                        }
                        //lmf
                        switchHotelUpMapper.updateHotelStatus(hotelId, up);
                        SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(2);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                        switchHotelUpLogEntity.setUsername("system-美团调用接口");
                        switchHotelUpLogMapper.insert(switchHotelUpLogEntity);
                        //开启上线
                        pushRoomPriceAndStatus(hotelId);
                    }
                    return setHotelSupplierBookableResult;
                }
            }
        } else {
            Map<String, Object> updateChannelVoMap = new HashMap<>();
            updateChannelVoMap.put("hotelIDs", new int[]{hotelId});
            updateChannelVoMap.put("cBookable", setHotelOnlineVo.getStatus());
            updateChannelVoMap.put("qBookable", setHotelOnlineVo.getStatus());
            updateChannelVoMap.put("channelABookable", setHotelOnlineVo.getStatus());//默认停售
            updateChannelVoMap.put("b2bBookable", setHotelOnlineVo.getStatus());//默认停售
            Result<Object> setHotelSupplierBookableResult = switchSubHotelInfoService.setHotelSupplierBookable(updateChannelVoMap, new ArrayList<SupplierTimeSaleInfoVo>());
            if (setHotelSupplierBookableResult.getCode() == CommonConstants.SUCCESS) {
                List<Integer> list = new ArrayList<>();
                list.add(hotelId);
                List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectById(list);
                for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                    String key = CommonConstants.SWITCH_SELLING_THE_HOUSE_TYPE + switchCreateRoomEntity.getMtHotelId() + "_" + switchCreateRoomEntity.getMtGoodId();
                    if (redisService.exists(key)) {
                        redisService.remove(key);
                    }
                }
                switchHotelUpMapper.updateHotelStatus(hotelId, 0);
                SwitchHotelUpLogEntity switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                switchHotelUpLogEntity.setCreateTime(new Date());
                switchHotelUpLogEntity.setGenre(2);
                switchHotelUpLogEntity.setHotelId(hotelId);
                switchHotelUpLogEntity.setUp(setHotelOnlineVo.getStatus());
                switchHotelUpLogEntity.setUsername("system");
                switchHotelUpLogMapper.insert(switchHotelUpLogEntity);

            }
            return setHotelSupplierBookableResult;
        }
    }

    /***
     * @Author: lmf
     * @Date: 2020/12/8
     * 批量更新售卖房型房态价格
     */
    @SneakyThrows
    @Override
    public Result<Object> batchUpdateRoomPriceAndStatus() {
        Example example = new Example(SwitchHotelUpEntity.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("up", 3);
        List<SwitchHotelUpEntity> switchHotelUpEntities = switchHotelUpMapper.selectByExample(example);
        List<List<SwitchHotelUpEntity>> lists = ListUtils.parititon(switchHotelUpEntities, 8);
        List<Integer> hotelIds=new ArrayList<>();

        for (List<SwitchHotelUpEntity> switchHotelUpEntityList : lists) {
            ExecutorService executorService = Executors.newFixedThreadPool(8);
            List<Future<Result<Integer>>> futureList=new ArrayList<>();
            List<SwitchPushRoomLogEntity> switchPushRoomLogEntities=new ArrayList<>();
            for (SwitchHotelUpEntity switchHotelUpEntity : switchHotelUpEntityList) {
                Future<Result<Integer>> future=executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                futureList.add(future);
                Thread.sleep(200);
            }
            executorService.shutdown();
            SwitchPushRoomLogEntity switchPushRoomLogEntity;
            //进行下一步
            while(true){
                if(executorService.isTerminated()){
                    for(Future<Result<Integer>> future:futureList){
                        Result<Integer> result=future.get();
                        log.info("========当前的结果为{}============",result.getData());
                        if(result.getData()!=0){
                            switchPushRoomLogEntity=new SwitchPushRoomLogEntity();
                            hotelIds.add(result.getData());
                            switchPushRoomLogEntity.setHotelId(result.getData());
                            switchPushRoomLogEntity.setCreateTime(new Date());
                            switchPushRoomLogEntities.add(switchPushRoomLogEntity);
                        }
                    }
                    break;
                }
            }
            if(switchPushRoomLogEntities.size()>0){
                switchPushRoomLogMapper.insertList(switchPushRoomLogEntities);
            }
        }
        return new Result<>();
    }


    /***
     * @Author: lmf
     * @Date: 2020/12/8
     * 多线程推送酒店房型数据
     */
    class threadPushRoomPriceAndStatusThread implements Callable<Result<Integer>> {
        SwitchHotelUpEntity switchHotelUpEntity;

        public threadPushRoomPriceAndStatusThread(SwitchHotelUpEntity switchHotelUpEntity) {
            this.switchHotelUpEntity = switchHotelUpEntity;
        }
        @Override
        public Result<Integer> call() throws Exception {
            int day=3;
            Map<String, Object> params = new HashMap<>();
            params.put("days", day);
            List<RoomDataEntityVo> roomDataEntityVo = new ArrayList<>();
            List<SwitchCreateRoomEntity> switchCreateRoomEntities = switchCreateRoomMapper.selectByHotelId(switchHotelUpEntity.getHotelId());
            tab:for (SwitchCreateRoomEntity switchCreateRoomEntity : switchCreateRoomEntities) {
                //2.获取美团房价
                params.put("goodsId", switchCreateRoomEntity.getMtGoodId());
                List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = getMtGoodsPrice(params);
                if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                    log.info("美团的产品价格日历数据为空");
                    continue tab;
                }
                //3.获取美团的房态
                params.put("hotelId", switchCreateRoomEntity.getMtHotelId());
                List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = getMtGoodsStatus(params, switchCreateRoomEntity.getMtGoodId());
                if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
                    continue tab;
                }

                //5.封装房型推送数据实体
                List<RoomDataEntityVo> roomDataEntityVos = null;
                try {
                    roomDataEntityVos = roomDataEntityVo(switchCreateRoomEntity, mtHotelGoodsPriceBaseDetailVos, mtHotelGoodsStatusDetailStateVos);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (!ObjectUtils.isEmpty(roomDataEntityVos) && roomDataEntityVos.size() > 0) {
                    roomDataEntityVo.addAll(roomDataEntityVos);
                }
            }
            Integer f=0;
            if(roomDataEntityVo.size()>0){
                List<List<RoomDataEntityVo>> RoomDataEntityVoLists = ListUtils.parititon(roomDataEntityVo, 299);
                BatchPushRoomVo batchPushRoomVo = new BatchPushRoomVo();
                Result<Object> resultq=new Result<>();
                log.info("==============酒店id为{}RoomDataEntityVoLists的长度为{}",switchHotelUpEntity.getHotelId(),roomDataEntityVo.size());
                for (List<RoomDataEntityVo> roomDataEntityVos1 : RoomDataEntityVoLists) {
                    batchPushRoomVo.setRoomDataEntitys(roomDataEntityVos1);
                    batchPushRoomVo.setHotelId(switchHotelUpEntity.getHotelId());
                    log.info("======酒店id为{}请求的json数据为{}",switchHotelUpEntity.getHotelId(), JSON.toJSONString(roomDataEntityVos1));
                    Result<Map<String, String>> result = switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                    log.info("=============酒店id为{}请求结果为{}",switchHotelUpEntity.getHotelId(),result.getMsg());
                    resultq.setMsg(result.getMsg());
                    if(result.getCode()==CommonConstants.SUCCESS){
                        f=1;
                    }else if(result.getMsg().toString().contains("数据重复")){
                        f=1;
                    }
                    if (result.getMsg().toString().contains("请求过于频繁")) {
                        try {
                            Thread.sleep(1000);
                            switchRoomPriceService.batchPushRoomData(batchPushRoomVo);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }else{
                log.info("==============酒店id为{}RoomDataEntityVoLists的长度为{}",switchHotelUpEntity.getHotelId(),roomDataEntityVo.size());
            }
            if(f==1){
                f=switchHotelUpEntity.getHotelId();
            }
            return new Result<>(f);
        }
    }

    public List<RoomDataEntityVo> roomDataEntityVo(SwitchCreateRoomEntity switchCreateRoomEntity, List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos, List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos) throws InvocationTargetException, IllegalAccessException {
        Map<String, List<SwitchPriceBaseSetEntity>> priceSetMap = switchPushRoomService.getOnlinePriceSet();
        List<RoomDataEntityVo> roomDataEntityVos = new ArrayList<>();
        //遍历美团价格
        RoomDataEntityVo roomDataEntityVo;
        RoomDataEntityVo qunarRoomDataEntityVo;
        RoomDataEntityVo b2bRoomDataEntityVo;
        Map<String, Object> map;
        double price = 0.0;
        double channelPrice = 0.0;
        SwitchHotelActiveTagEntity switchHotelActiveTagEntity;
        RoomPriceModelVo roomPriceModelVo;
        RoomPriceModelVo qunarroomPriceModelVo;
        RoomPriceModelVo b2broomPriceModelVo;
        RoomPriceModelVo channelroomPriceModelVo;
        RoomStatusModelVo roomStatusModelVo;
        RoomInventoryModelVo roomInventoryModelVo;
        //渠道名称
        String channel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.CTRIP.getName());
        String QunarChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.QUNAR.getName());
        String b2bChannel = StringUtil.firstToUpperCase(SwitchChannelNameEnums.BIG_B2B.getName());
        for (MtHotelGoodsPriceBaseDetailVo mtHotelGoodsPriceBaseDetailVo : mtHotelGoodsPriceBaseDetailVos) {
            //携程
            roomDataEntityVo = new RoomDataEntityVo();
            roomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //去哪儿
            qunarRoomDataEntityVo = new RoomDataEntityVo();
            qunarRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //B2B
            b2bRoomDataEntityVo = new RoomDataEntityVo();
            b2bRoomDataEntityVo.setRoomId(switchCreateRoomEntity.getRoomId());
            //针对统一的进行价格公式计算
            map = new HashMap<>();
            //判断是否参加促销活动
            switchHotelActiveTagEntity = switchHotelActiveTagMapper.selectHotelIdAndRoomIdAndTime(switchCreateRoomEntity.getHotelId(), switchCreateRoomEntity.getRoomId(), mtHotelGoodsPriceBaseDetailVo.getDate());
            if (ObjectUtils.isEmpty(switchHotelActiveTagEntity)) {
                map = switchPushRoomService.getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
            } else {
                String currentWeekDay = DateUtil.dayForWeek(mtHotelGoodsPriceBaseDetailVo.getDate());
                //促销
                if (switchHotelActiveTagEntity.getWeek().contains("每天") || switchHotelActiveTagEntity.getWeek().contains(currentWeekDay)) {
                    map = switchPushRoomService.getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), switchHotelActiveTagEntity);
                } else {//判断当前周几，是否符合促销活动
                    map = switchPushRoomService.getPriceV2(priceSetMap, mtHotelGoodsPriceBaseDetailVo.getSalePrice(), mtHotelGoodsPriceBaseDetailVo.getSubPrice(), null);
                }
            }
            //如果价格符合公式，房态可预定 有库存就进行设置推送
            price = Double.parseDouble(map.get("ctripPrice").toString());
            channelPrice = Double.parseDouble(map.get("qunarPrice").toString());
            //房价推送实体
            //携程
            roomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            roomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //去哪儿
            qunarRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            qunarRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //b2b
            b2bRoomDataEntityVo.setStartDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            b2bRoomDataEntityVo.setEndDate(mtHotelGoodsPriceBaseDetailVo.getDate());
            //携程房价实体
            roomPriceModelVo = new RoomPriceModelVo();
            roomPriceModelVo.setRoomPrice(price);
            roomPriceModelVo.setCurrency("CNY");
            //去哪儿房价实体
            qunarroomPriceModelVo = new RoomPriceModelVo();
            qunarroomPriceModelVo.setRoomPrice(channelPrice);
            qunarroomPriceModelVo.setCurrency("CNY");
            //b2b房价实体
            b2broomPriceModelVo = new RoomPriceModelVo();
            org.apache.commons.beanutils.BeanUtils.copyProperties(b2broomPriceModelVo, qunarroomPriceModelVo);
            //channel房价实体
            channelroomPriceModelVo = new RoomPriceModelVo();
            org.apache.commons.beanutils.BeanUtils.copyProperties(channelroomPriceModelVo, qunarroomPriceModelVo);
            //携程
            roomPriceModelVo.setChannel(channel);
            roomDataEntityVo.setRoomPriceModel(roomPriceModelVo);
            //去哪儿
            qunarroomPriceModelVo.setChannel(QunarChannel);
            qunarRoomDataEntityVo.setRoomPriceModel(qunarroomPriceModelVo);
            //b2b
            b2broomPriceModelVo.setChannel(b2bChannel);
            b2bRoomDataEntityVo.setRoomPriceModel(b2broomPriceModelVo);
            if (mtHotelGoodsStatusDetailStateVos.size() < 1) {
                String endTime=DateUtil.getNextDays(15);
                roomStatusModelVo = new RoomStatusModelVo();
                if(DateUtil.commpareDay(mtHotelGoodsPriceBaseDetailVo.getDate(),endTime)){
                    roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                }
                roomStatusModelVo.setChannel(channel);
                roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                //库存推送实体
                roomInventoryModelVo = new RoomInventoryModelVo();
                //可以取消设置为保留房 不可以取消设置为非保留房
                roomInventoryModelVo.setPreservedQuantity(0);
                roomInventoryModelVo.setUnPreservedQuantity(1);
                roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                roomInventoryModelVo.setChannel(channel);
                roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                roomDataEntityVos.add(roomDataEntityVo);
            } else {
                //遍历房态
                for (MtHotelGoodsStatusDetailStateVo mtHotelGoodsStatusDetailStateVo : mtHotelGoodsStatusDetailStateVos) {
                    String endTime=DateUtil.getNextDays(15);
                    //匹配同一天日期
                    if (mtHotelGoodsPriceBaseDetailVo.getDate().equals(mtHotelGoodsStatusDetailStateVo.getDate())) {
                        //房态推送实体
                        roomStatusModelVo = new RoomStatusModelVo();
                        if(DateUtil.commpareDay(mtHotelGoodsStatusDetailStateVo.getDate(),endTime)){
                            if (mtHotelGoodsStatusDetailStateVo.getStatus() == 1) {
                                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.SALE.getCode());
                            } else {
                                roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                            }
                        }else{
                            roomStatusModelVo.setSaleStatus(SwitchSaleStatusEnums.FULL.getCode());
                        }
                        roomStatusModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomStatusModel(roomStatusModelVo);
                        //房量推送实体
                        roomInventoryModelVo = new RoomInventoryModelVo();
                        //可以取消设置为保留房 不可以取消设置为非保留房
                        roomInventoryModelVo.setPreservedQuantity(0);
                        roomInventoryModelVo.setUnPreservedQuantity(1);
                        roomInventoryModelVo.setPushUnPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        roomInventoryModelVo.setPushPreservedType(SwitchPushPreservedTypeEnums.TOTAL.getCode());
                        roomInventoryModelVo.setAutoCloseRoom(SwitchAutoCloseRoomEnums.YES.getCode());
                        roomInventoryModelVo.setChannel(channel);
                        roomDataEntityVo.setRoomInventoryModel(roomInventoryModelVo);
                        roomDataEntityVos.add(roomDataEntityVo);
                        roomDataEntityVos.add(qunarRoomDataEntityVo);
                        roomDataEntityVos.add(b2bRoomDataEntityVo);
                    }
                }
            }
        }
        return roomDataEntityVos;
    }

    /**
     * 获取美团产品价格
     */
    public List<MtHotelGoodsPriceBaseDetailVo> getMtGoodsPrice(Map<String, Object> params) {
        List<MtHotelGoodsPriceBaseDetailVo> mtHotelGoodsPriceBaseDetailVos = new ArrayList<>();
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_PRICE_BY_HOTEL_ID.getUrl();
        try {
            Result<List<MtHotelGoodsPriceBaseDetailVo>> result1 = switchRestTempaleUtilsService.sendPostRequestGetGoodsPrice(url, params);
            if (result1.getCode() == CommonConstants.SUCCESS) {
                mtHotelGoodsPriceBaseDetailVos = result1.getData();
                if (ObjectUtils.isEmpty(mtHotelGoodsPriceBaseDetailVos) || mtHotelGoodsPriceBaseDetailVos.size() < 1) {
                    log.info("=============美团的产品价格日历返回数据为空=====================");
                } else {
                    log.info("=============美团的产品价格日历返回数据成功，条数为{}", mtHotelGoodsPriceBaseDetailVos.size());
                }
            }
        } catch (Exception e) {
            log.info("=============获取产品价格日历发生的异常为{}============", e.getMessage());
            return new ArrayList<>();
        }
        return mtHotelGoodsPriceBaseDetailVos;
    }

    /**
     * 获取美团房态
     */
    public List<MtHotelGoodsStatusDetailStateVo> getMtGoodsStatus(Map<String, Object> params, int mtGoodId) {
        String url = MEI_TUAN_URL + MtRequestUrlEnums.GET_MT_GOODS_STATUS_BY_DAYS.getUrl();
        List<MtHotelGoodsStatusDetailStateVo> mtHotelGoodsStatusDetailStateVos = new ArrayList<>();
        try {
            Result<Map<Integer, List<MtHotelGoodsStatusDetailStateVo>>> result2 = switchRestTempaleUtilsService.sendPostRequestGetGoodsStatus(url, params);
            if (result2.getCode() == CommonConstants.SUCCESS) {
                Map<Integer, List<MtHotelGoodsStatusDetailStateVo>> map = result2.getData();
                if (ObjectUtils.isEmpty(map)) {
                    log.info("=============美团的产品房态返回数据为空=====================");
                } else {
                    //产品房态
                    if (map.containsKey(mtGoodId)) {
                        mtHotelGoodsStatusDetailStateVos = map.get(mtGoodId);
                        log.info("==========产品房态===========，条数为{}", mtHotelGoodsStatusDetailStateVos.size());
                    }
                }
            }
        } catch (Exception e) {
            log.info("========获取美团房态发生的异常为{}==================", e.getMessage());
        }
        return mtHotelGoodsStatusDetailStateVos;
    }
    /***
    * @Author: lmf
    * @Date: 2020/12/24
     * 获取酒店列表
     * @param genre
    */
    @Override
    public Result<Object> getUpHotelRpOrFtAsc(Integer genre) {
       int rpRate=7;
        String key=CommonConstants.SYSTEM_BASE_SET_TO_MEITUAN_RP_RATE;
        if(redisService.exists(key)){
            rpRate= (int) redisService.get(key);
        }
        int ftRate=3;
        key=CommonConstants.SYSTEM_BASE_SET_TO_MEITUAN_FT_RATE;
        if(redisService.exists(key)){
            ftRate= (int) redisService.get(key);
        }
        List<Integer> list=new ArrayList<>();
        List<Integer> orderList=new ArrayList<>();
        int count=0;
        //节假日只跑有订单的酒店
        if(redisService.exists("switch_holiday_control_hotel")){
            //间夜量
            //在指定时间段内，只跑有订单数据
            //判断当前的时间段
            Calendar calendar=Calendar.getInstance();
            int hour=calendar.get(Calendar.HOUR_OF_DAY);
            int minute=calendar.get(Calendar.MINUTE);
            log.info("======当前的时间点为{},分钟为{}===",hour,minute);
            if(hour == 0 && minute <= 40){
                log.info("=============当前的时间点处于凌晨===================");
                list = switchHotelUpMapper.getUpHotelList();
                orderList=switchHotelUpMapper.getOrderHotelList();
            }else{
                log.info("=============当前的时间点处于白天===================");
                list = switchHotelUpMapper.getUpHotelAsc();
                orderList=switchHotelUpMapper.getOrderHotelList();
            }
        }else{
            list = switchHotelUpMapper.getUpHotelAsc();
            orderList=switchHotelUpMapper.getOrderHotelList();
        }
        if(list.size()>orderList.size()){
            count=list.size();
        }else{
            count=orderList.size();
        }
        HashSet<Integer> hs1=new HashSet<>(list);
        HashSet<Integer> hs2=new HashSet<>(orderList);
        hs1.removeAll(hs2);
        List<Integer> otherList=new ArrayList<>();
        otherList.addAll(hs1);
        //待分配的酒店总个数
        log.info("===============总酒店个数为{}=====",count);
        int ftRateNUm=(int) Math.ceil(count/(rpRate+ftRate)*ftRate);;
        log.info("===============供房态调用的酒店个数为{}=====",ftRateNUm);
        int rpRateNum= count-ftRateNUm;
        log.info("===============供rp调用的酒店个数为{}=====",rpRateNum);
        if(orderList.size()<=ftRateNUm){
            int size=ftRateNUm-orderList.size();
            count=otherList.size();
            for(int i=0;i<size;i++){
                int index= (int) (Math.random()*count);
                orderList.add(otherList.get(index));
                otherList.remove(otherList.get(index));
                count--;
            }
        }else{
            int size=orderList.size()-ftRateNUm;
            count=orderList.size();
            for(int i=0;i<size;i++){
                int index= (int) (Math.random()*count);
                otherList.add(orderList.get(index));
                orderList.remove(orderList.get(index));
                count--;
            }
        }
        if(redisService.exists("switch_rp_list")){
            log.info("=========走缓存============");
            String jsonList= (String) redisService.get("switch_rp_list");
            otherList=JacksonUtil.jsonToList(jsonList,Integer.class);
            jsonList= (String) redisService.get("switch_ft_list");
            orderList=JacksonUtil.jsonToList(jsonList,Integer.class);
        }else{
            log.info("=========走数据库============");
            redisService.set("switch_rp_list",GsonUtils.GsonString(otherList),(long)1000);
            redisService.set("switch_ft_list",GsonUtils.GsonString(orderList),(long)1000);
        }
        if(genre==1){//1 获取rp酒店数据
           log.info("===========rp的酒店数据为{}=====",otherList);
            log.info("===========rp的酒店数据长度为{}=====",otherList.size());
            return new Result<>(GsonUtils.GsonString(otherList),"success");
        }else{//2 获取房态数据
            log.info("===========ft的酒店数据为{}=====",orderList);
            log.info("===========ft的酒店数据长度为{}=====",orderList.size());
            return new Result<>(GsonUtils.GsonString(orderList),"success");
        }
    }
    /***
    * @Author: lmf
    * @Date: 2020/12/25
     * 获取售卖的酒店有房型列表
    */
    @Override
    public Result<Object> checkSaleHotelRoomId() {
        String key="switch_sale_hotel_having_room_list";
        List<Integer> hotelIds=new ArrayList<>();
        if(redisService.exists(key)){
            String json= (String) redisService.get(key);
            hotelIds=JacksonUtil.jsonToList(json,Integer.class);
            if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
                hotelIds=switchHotelUpMapper.selectSaleHotelListByRoomList();
                redisService.set(key, JSON.toJSONString(hotelIds));
            }
        }else{
            hotelIds=switchHotelUpMapper.selectSaleHotelListByRoomList();
            redisService.set(key, JSON.toJSONString(hotelIds));
        }
        log.info("==========hotelIds的长度为{}========",hotelIds.size());
        int f=0;
        List<Integer> masterBaiscRoomId=new ArrayList<>();
        for(int i=0;i<hotelIds.size();i++){
            int hotelId=hotelIds.get(0);
            log.info("===========hotelId为{}=======",hotelId);
            //先获取美团的id
            String mtHotelId="";
            Map<String,String> params=new HashMap<>();
            params.put("masterHotelId", String.valueOf(hotelId));
            String url= CommonUrlConstants.COMPARE_HOST+"/"+ CompareRequestUrlEnums.GET_COMPARE_MT_HOTEL_ID.getUrl();
            Result result;
            try {
                result= switchRestTempaleUtilsService.sendPOstRequestByGetMtHotelId(url,params);
                if(result.getCode()==CommonConstants.SUCCESS){
                    mtHotelId=result.getData().toString();
                    log.info("==========美团的酒店id为============{}",mtHotelId);
                    hotelIds.remove(0);
                    url = CommonUrlConstants.MEITUAN_HOST+"/"+ MtRequestUrlEnums.GET_MT_GOODS_BY_HOTEL_ID.getUrl();
                    Map<String, Integer> param = new HashMap<>();
                    param.put("hotelId", Integer.valueOf(mtHotelId));
                    Map<String, List<MtHotelGoodsDto>> goodsMap = new HashMap<>();
                    try {
                        result = switchRestTempaleUtilsService.sendPostRequest(url, param);
                        if (result.getCode() != CommonConstants.SUCCESS) {
                            log.info("==========获取美团的产品列表数据失败,错误原因是{}=============", result.getMsg());
                            return new Result<>("获取美团的产品列表数据失败", CreateBasicRoomStatusEnums.CATCH.getCode());
                        } else {
                            if (!ObjectUtils.isEmpty(result.getData())) {
                                goodsMap = (Map<String, List<MtHotelGoodsDto>>) result.getData();
                                for(Map.Entry<String,List<MtHotelGoodsDto>> entry:goodsMap.entrySet()){
                                    log.info("====================真实的房型id为{}==========",entry.getKey());
                                    List<MtHotelGoodsDto> mtHotelGoodsDtos=entry.getValue();
                                    boolean isCanCreeate=false;
                                    //判断是否有符合创建的产品
                                    switchTab:for(MtHotelGoodsDto mtHotelGoodsDto:mtHotelGoodsDtos){
                                        if(mtHotelGoodsDto.getMtGoodsStatus()==3){
                                            continue switchTab;
                                        }
                                        //过滤钟点房
                                        if (mtHotelGoodsDto.getMtGoodsType() ==2) {
                                            continue switchTab;
                                        }
                                        //过滤掉需要身份证验证的
                                        if(mtHotelGoodsDto.getMtNeedIdentityCard()==1){
                                            continue switchTab;
                                        }
                                        /**
                                         * 过滤掉需要连住的产品
                                         * 如果最少入住天数>1 产品暂时不要
                                         * 如果最少预定间数>1 产品暂时不要
                                         */
                                        List<MtHotelGoodsBookRuleDto> mtHotelGoodsBookRuleDtos=mtHotelGoodsDto.getBookRuleList();
                                        if(!ObjectUtil.isEmpty(mtHotelGoodsBookRuleDtos)&&mtHotelGoodsBookRuleDtos.size()>0){
                                            for(MtHotelGoodsBookRuleDto mtHotelGoodsBookRuleDto:mtHotelGoodsBookRuleDtos){
                                                if(mtHotelGoodsBookRuleDto.getMtSerialCheckinMin()>1||mtHotelGoodsBookRuleDto.getMtRoomCountMin()>1){
                                                    continue switchTab;
                                                }
                                            }
                                        }
                                        //过滤掉第三方开票方
                                        MtHotelGoodsInvoiceDto mtHotelGoodsInvoiceDto=mtHotelGoodsDto.getInvoice();
                                        if(!ObjectUtils.isEmpty(mtHotelGoodsInvoiceDto)){
                                            if(mtHotelGoodsInvoiceDto.getInvoiceMode()==3||mtHotelGoodsInvoiceDto.getInvoiceMode()==2){
                                                continue switchTab;
                                            }
                                        }
                                        //过滤掉产品名称需要证件的产品
                                        if(mtHotelGoodsDto.getMtGoodsName().contains("护士证")){
                                            continue switchTab;
                                        }
                                        if(mtHotelGoodsDto.getMtGoodsName().contains("户籍")){
                                            continue switchTab;
                                        }
                                        if(mtHotelGoodsDto.getMtGoodsName().contains("资格证")){
                                            continue switchTab;
                                        }
                                        if(mtHotelGoodsDto.getMtGoodsName().contains("学生证")){
                                            continue switchTab;
                                        }
                                        if(mtHotelGoodsDto.getMtGoodsName().contains("证件")){
                                            continue switchTab;
                                        }
                                        if(mtHotelGoodsDto.getMtGoodsName().contains("零点后入住")){
                                            continue switchTab;
                                        }
                                        isCanCreeate=true;
                                    }
                                    if(isCanCreeate){
                                        url =CommonUrlConstants.COMPARE_HOST+ CompareRequestUrlEnums.GET_HOTEL_BASIC_ROOM_INFO_BY_MT_HOTEL_ID_AND_MT_ROOM_ID.getUrl();
                                        param.put("mtHotelId", Integer.valueOf(mtHotelId));
                                        param.put("mtRoomId",Integer.valueOf(entry.getKey()));
                                        Result<CompareHotelBasicRoom> result1 = switchRestTempaleUtilsService.sendPostRequestByGetSwitchHotelIdAndRoomId(url, param);
                                        CompareHotelBasicRoom compareHotelBasicRoom=result1.getData();
                                        if(!ObjectUtils.isEmpty(compareHotelBasicRoom)){
                                            log.info("===========有映射关系修改创建数据==============");
                                            //更新创建物理房型表状态
                                            masterBaiscRoomId.add(Integer.valueOf(compareHotelBasicRoom.getSwitchHotelRoomId()));
                                        }
                                    }
                                }
                            }
                        }
                    } catch (Exception e) {
                        log.info("===============获取美团的产品列表数据，产生的异常为{}=======", e.getMessage());
                        return new Result<>("获取美团的产品列表数据失败", CreateBasicRoomStatusEnums.CATCH.getCode());
                    }
                }
            }catch (Exception e){
                log.info("=======获取美团酒店id出现异常==============");
            }
            f++;
            if(f>4){
                break;
            }
        }
        if(!ObjectUtils.isEmpty(masterBaiscRoomId)&&masterBaiscRoomId.size()>0){
            switchCreateBasicRoomMapper.updateBatchCreateState(StringUtils.join(masterBaiscRoomId,","));
        }
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            hotelIds=switchHotelUpMapper.selectSaleHotelListByRoomList();
        }
        redisService.set(key, JSON.toJSONString(hotelIds));
        return new Result<>();
    }
    /***
    * @Author: lmf
    * @Date: 2020/12/31
     * 获取没有订单酒店的数据并且设置为停售
    */
    @Override
    public Result<Object> bookTimeCloseNoOrderHotelList() {
        List<Integer> hotelIds=switchHotelUpMapper.getNoOrderHotelList();
        //0点异步通道价格关闭,50分钟
        redisService.setUnit(CallbackConstants.CLOSE_MT_CB_PRICE,1,50L,TimeUnit.MINUTES);
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }else{
            new BookTimeHotelDownThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }

    class BookTimeHotelDownThread implements Runnable{
        private  List<Integer> hotelIds;

        public BookTimeHotelDownThread(List<Integer> list) {
            this.hotelIds = list;
        }

        @Override
        public void run() {
            List<List<Integer>> lists=ListUtils.parititon(this.hotelIds,50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
            for(List<Integer> list:lists){
                //设置停售
                Integer[] hotelList = new Integer[list.size()];
                Result<Object> result = pushHotelStatus(list.toArray(hotelList), 0);
                if(result.getCode()==CommonConstants.SUCCESS){
                    //更新上架表的状态
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),4);
                    //添加操作日志
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                    switchHotelUpLogEntities=new ArrayList<>();
                    for(Integer hotelId:list){
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(4);
                        switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点停售");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                    }
                    switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                    log.info("=========关闭售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                }else if(result.getMsg().toString().contains("频繁")){
                    try {
                        Thread.sleep(10000);
                        result = pushHotelStatus(list.toArray(hotelList), 0);
                        if(result.getCode()==CommonConstants.SUCCESS){
                            //更新上架表的状态
                            switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),4);
                            //添加操作日志
                            SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                            switchHotelUpLogEntities=new ArrayList<>();
                            for(Integer hotelId:list){
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(hotelId);
                                switchHotelUpLogEntity.setUp(4);
                                switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点停售");
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                            }
                            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                            log.info("=========关闭售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //刪除緩存
            //删除酒店缓存
            if(redisService.exists("goods_query_job_up_hotel_data")){
                redisService.remove("goods_query_job_up_hotel_data");
            }
            //删除房态队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus");
            }
            //删除价格队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlprice")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlprice");
            }
        }
    }
    /***
    * @Author: lmf
    * @Date: 2020/12/31
     * 开启暂时关闭的酒店数据列表
    */
    @Override
    public Result<Object> bookTimeStartNoOrderHotelList() {
        List<Integer> hotelIds=switchHotelUpMapper.getBookTimeDownHotelList();
        if(ObjectUtils.isEmpty(hotelIds)||hotelIds.size()<1){
            return new Result<>();
        }else{
            new BookTimeHotelUpThread(hotelIds).run();
            return new Result<>("异步执行中",CommonConstants.SUCCESS);
        }
    }

    class BookTimeHotelUpThread implements Runnable{
        private List<Integer> hotelIds;

        public BookTimeHotelUpThread(List<Integer> hotelIds) {
            this.hotelIds = hotelIds;
        }
        @Override
        public void run() {
            List<List<Integer>> lists=ListUtils.parititon(this.hotelIds,50);
            List<SwitchHotelUpLogEntity> switchHotelUpLogEntities=null;
            for(List<Integer> list:lists){
                //设置停售
                Integer[] hotelList = new Integer[list.size()];
                Result<Object> result = pushHotelStatus(list.toArray(hotelList), 1);
                if(result.getCode()==CommonConstants.SUCCESS){
                    //更新上架表的状态
                    switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),3);
                    //添加操作日志
                    SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                    switchHotelUpLogEntities=new ArrayList<>();
                    for(Integer hotelId:list){
                        switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                        switchHotelUpLogEntity.setCreateTime(new Date());
                        switchHotelUpLogEntity.setGenre(1);
                        switchHotelUpLogEntity.setHotelId(hotelId);
                        switchHotelUpLogEntity.setUp(4);
                        switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点开售");
                        switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                        SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                        switchHotelUpEntity.setHotelId(hotelId);
                        ExecutorService executorService = Executors.newFixedThreadPool(1);
                        executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                        executorService.shutdown();
                        try {
                            Thread.sleep(300);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                    log.info("=========开启售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                }else if(result.getMsg().toString().contains("频繁")){
                    try {
                        Thread.sleep(10000);
                        result = pushHotelStatus(list.toArray(hotelList), 1);
                        if(result.getCode()==CommonConstants.SUCCESS){
                            //更新上架表的状态
                            switchHotelUpMapper.updateHotelStatis(StringUtils.join(list, ","),3);
                            //添加操作日志
                            SwitchHotelUpLogEntity switchHotelUpLogEntity = null;
                            switchHotelUpLogEntities=new ArrayList<>();
                            for(Integer hotelId:list){
                                switchHotelUpLogEntity = new SwitchHotelUpLogEntity();
                                switchHotelUpLogEntity.setCreateTime(new Date());
                                switchHotelUpLogEntity.setGenre(1);
                                switchHotelUpLogEntity.setHotelId(hotelId);
                                switchHotelUpLogEntity.setUp(3);
                                switchHotelUpLogEntity.setUsername("admin-无订单酒店0-5点开售");
                                switchHotelUpLogEntities.add(switchHotelUpLogEntity);
                                SwitchHotelUpEntity switchHotelUpEntity=new SwitchHotelUpEntity();
                                switchHotelUpEntity.setHotelId(hotelId);
                                ExecutorService executorService = Executors.newFixedThreadPool(1);
                                executorService.submit(new threadPushRoomPriceAndStatusThread(switchHotelUpEntity));
                                executorService.shutdown();
                                try {
                                    Thread.sleep(300);
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                            }
                            switchHotelUpLogMapper.insertList(switchHotelUpLogEntities);
                            log.info("=========开启售卖本次推送的酒店数据为{},推送结果为{}============", StringUtils.join(list, ","),result.getMsg());
                        }
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                try {
                    Thread.sleep(10000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            //删除酒店缓存
            if(redisService.exists("goods_query_job_up_hotel_data")){
                redisService.remove("goods_query_job_up_hotel_data");
            }
            //删除房态队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlstatus");
            }
            //删除价格队列
            if(redisService.exists("pop_all_sale_room_about_mt_hotel_ids_for_rlprice")){
                redisService.remove("pop_all_sale_room_about_mt_hotel_ids_for_rlprice");
            }
        }

    }


}
